<?php
$this->display('public/header.phtml', array(
    "title"    => "内容列表",
    "styles"   => '',
    "crumbArr" => array(
        array("title" => "内容列表"),
    ),
));
?>

<div class="row">
    <div class="col-xs-12">
        <div class="row">
            <div class="col-xs-12">
                <form class="form-inline form-search">
                    <div class="form-group">
                        <label for="nameInput">内容名称</label>
                        <input type="text" name="content_title"/>
                    </div>
                    <div class="form-group">
                        <label for="nameInput">状态</label>
                        <select name="status">
                            <?php foreach ($statusConfig as $key => $value): ?>
                                <option value="<?php echo $key; ?>"><?php echo $value['name']; ?></option>
                            <?php endforeach; ?>
                        </select>
                    </div>
                    <button type="submit" class="btn-sm btn btn-primary">搜 索</button>
                    <a class="btn btn-sm btn-primary" href="/admin/content/add/">增加内容</a>
                </form>
                <div class="space-4"></div>

                <!-- <div class="dataTables_borderWrap"> -->
                <table id="sample-table-1" class="table table-striped table-bordered table-hover">
                    <thead>
                        <tr>
                            <th>编号</th>
                            <th>状态</th>
                            <th>分类</th>
                            <th>标题</th>
                            <th>图片</th>
                            <th>点赞/鄙视</th>
                            <th>增加时间</th>
                            <th>操作</th>
                        </tr>
                    </thead>

                    <tbody>
                        <?php foreach ($listdata as $row): ?>
                            <tr>
                                <td><?php echo $row['content_id']; ?></td>
                                <td><?php echo $row['status_name']; ?></td>
                                <td><?php echo $row['category']['category_name']; ?></td>
                                <td><?php echo $row['content_title']; ?></td>
                                <td>
                                    <?php if ($row['content_image']): ?>
                                        <img src="<?php echo $row['content_image']; ?>" height="50" />
                                    <?php endif ?>
                                </td>
                                <td><?php echo $row['praise_total']; ?>/<?php echo $row['despise_total']; ?></td>
                                <td><?php echo date("Y-m-d H:i:s", $row['add_time']); ?></td>
                                <td>
                                    <div class="hidden-sm hidden-xs action-buttons">
                                        <a href="/admin/content/edit/?content_id=<?php echo $row['content_id'] ?>">
                                            编辑
                                        </a>
                                        <a href="<?php echo \Bootstrap::getConfig('www.site.host'); ?>/content/<?php echo $row['content_id'] ?>.html" target="_blank">
                                            预览
                                        </a>
                                        <a class="delete-content" href="javascript:void(0);" data-id="<?php echo $row['content_id'] ?>">
                                            删除
                                        </a>
                                    </div>
                                </td>
                            </tr>
                        <?php endforeach; ?>
                    </tbody>
                </table>
                <?php $this->display('public/pagination.phtml', array('paginator' => $this->paginator->style1())); ?>
            </div>
        </div>
    </div><!-- /.col -->
</div><!-- /.row -->

<?php
$this->display("public/footer.phtml", array(
    "scripts" => ''
));
?>
<script type="text/javascript">
    $(document).ready(function () {
        $(".delete-content").click(function () {
            let id = $(this).attr('data-id');
            let c = confirm("确定要删除id为 " + id + "的内容吗？");
            if (!c) {
                return false;
            }
            storeHttpRequest.request({
                dataType: "json",
                uri: "/admin/content/delete/?id=" + id,
                isOK: function (result) {
                    alert(result.message);
                    location.reload();
                },
            });
        });
    });
</script>
<?php $this->display("public/list_footer.phtml"); ?>
<?php $this->display("public/footer_body.phtml"); ?>